﻿@using System.Threading
@using EveKillboard
@using EveKillboard.Content
@using EveKillboard.Core.Services
@using EveKillboard.Core.Views
@model EntityStats
@{
    if (!ViewData.ContainsKey("isKill")) { ViewData.Add("isKill", true); }
    var isCharacter = Model is ICharacterStats;
    var isCorp = Model is ICorporationStats;
    var isAlliance = Model is IAllianceStats;
    var charCorpInternalId = 0;
    var corpAllyInternalId = 0; 
    CharacterInfos charInfos = null;
    CorporationInfos corpInfos = null;
    if (isCharacter){
        charInfos = ViewData.ContainsKey("charInfos") ? ViewData["charInfos"] as CharacterInfos : null;
        charCorpInternalId = ViewData.ContainsKey("charCorpInternalId") ? (int) ViewData["charCorpInternalId"] : 0;
    }
    else if (isCorp){
        corpInfos = ViewData.ContainsKey("corpInfos") ? ViewData["corpInfos"] as CorporationInfos : null;
        corpAllyInternalId = ViewData.ContainsKey("corpAllyInternalId") ? (int)ViewData["corpAllyInternalId"] : 0;
    }
    var efficiency = (1 - Model.LossesValue.GetValueOrDefault(0) / (Model.KillsValue > 0 ? Model.KillsValue : 1)) < 0 ? 0 : 1 - Model.LossesValue.GetValueOrDefault(0) / (Model.KillsValue > 0 ? Model.KillsValue : 1);
}
<div class="content">
    <div id="entityHeader">
        <div id="entityImage" style="display: inline-block; vertical-align: top;">
            <img src="@string.Format("{0}", isCharacter ? string.Format("http://image.eveonline.com/Character/{0}_128.jpg", Model.EveId) : isCorp ? string.Format("http://image.eveonline.com/Corporation/{0}_128.png", Model.EveId) : isAlliance ? string.Format("http://image.eveonline.com/Alliance/{0}_128.png", Model.EveId) : null)" title="@string.Format("{0}", Model.Name)"  alt width="128px" height="128px">
        </div>
        <div style="display: inline-block; vertical-align: top;">
            <div>@Model.Name</div>
            @if (isCharacter && charInfos != null){
                <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : ", Labels.corporation)
                    <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Corporation", "Killboard"), charCorpInternalId)">@charInfos.CorporationName</a>
                </div>
            }
            @if (isCorp && corpInfos != null){
                <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : ", Labels.alliance)
                    @if (!string.IsNullOrEmpty(corpInfos.AllianceName)){
                        <a class="evelink" href="@string.Format("{0}/{1}", Url.Action("Alliance", "Killboard"), corpAllyInternalId)">@corpInfos.AllianceName</a>
                    }
                    else{ <label>@Labels.none</label> }
                </div>
            }
            <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : {1}", Labels.kills, Model.KillsCount) (@string.Format(EveKillboard.Core.EveCustomFormatProvider.Instance, "{0:N2}", Model.KillsValue > 0 ? Model.KillsValue : 0))</div>
            <div>@string.Format(Thread.CurrentThread.CurrentUICulture, "{0} : {1}", Labels.losses, Model.LossesCount) (@string.Format(EveKillboard.Core.EveCustomFormatProvider.Instance, "{0:N2}", Model.LossesValue > 0 ? Model.LossesValue : 0))</div>
            <div>@string.Format(Thread.CurrentThread.CurrentCulture, "{0} : {1:P2}", Labels.efficiency, efficiency.GetValueOrDefault(0))</div>
        </div>
        <div style="display: inline-block; vertical-align: top; text-align: center;">
            <div>@string.Format(Thread.CurrentThread.CurrentUICulture,"{0}", Labels.days_activity)</div>
            <canvas id="entityActivity" width="120px" height="100px" ></canvas>
        </div>
        @if(isCharacter || isCorp){
        <div style="display: inline-block; vertical-align: top;">
            <div>@string.Format(Thread.CurrentThread.CurrentUICulture,"{0}", Labels.contribution)</div>
            <canvas id="contribution" width="60px" height="50px" title="@string.Format(Thread.CurrentThread.CurrentUICulture, "{0}", isCharacter ? Labels.corporation_contribution : Labels.alliance_contribution)"></canvas>
        </div>    
        }
    </div>
    @{ var isKill = ViewData.ContainsKey("isKill") && (bool)ViewData["isKill"]; }
    <div id="activity" style="display: inline-block; padding-top: 5px" >
        <div id="listContent" style="display: block; width: 850px;">
            <img id="listLoading" src alt width="16px" height="11px"/>
        </div>
    </div>
    <div class="rightContent">
        @if (isCorp){
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.month_top_killers, DateTime.Today.ToString("MMMM"))</div>
            <div class="topViewlistContent" id="topCharacterKillsMonthContent"><img id="topCharacterKillsMonthLoading" src alt width="16px" height="11px"/></div>
        </div>
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.month_top_losers, DateTime.Today.ToString("MMMM"))</div>
            <div class="topViewlistContent" id="topCharacterLossesMonthContent"><img id="topCharacterLossesMonthLoading" src alt width="16px" height="11px"/></div>
        </div>
        }
        else if (isAlliance){
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.month_top_corps, DateTime.Today.ToString("MMMM"))</div>
            <div class="topViewlistContent" id="topAllianceCorpKillsContent"><img id="topAllianceCorpKillsLoading" src alt width="16px" height="11px"/></div>
        </div>
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.month_top_corp_losers, DateTime.Today.ToString("MMMM"))</div>
            <div class="topViewlistContent" id="topAllianceCorpLossesContent"><img id="topAllianceCorpLossesLoading" src alt width="16px" height="11px"/></div>
        </div>
        }
        else if (isCharacter){
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.character_ships_used)</div>
            <div class="topViewlistContent" id="topCharacterShipsContent"><img id="topCharacterShipsLoading" src alt width="16px" height="11px"/></div>
        </div>
        <div class="topViewContainer">
            <div class="topViewLabel gradientheader">@string.Format(Thread.CurrentThread.CurrentUICulture, Labels.character_favorite_prey)</div>
            <div class="topViewlistContent" id="topCharacterShipGroups"><img id="topCharacterShipGroupsLoading" src alt width="16px" height="11px"/></div>
        </div>
        }
    </div>
</div>
@section scripts {
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
    @if(Helper.IsDebug()){
        <script src="@Url.Content("~/Content/scripts/stats.js")" type="text/javascript"></script>
    }
    else{
        <script src="@Url.Content("~/Content/scripts/min/stats.min.js")" type="text/javascript"></script>
    }
    @if (isCorp){
    <script type="text/javascript" >
        $(document).ready(function () {
            evekillboard.loadCorporationCharactersKillsMonth( @Html.Raw(string.Format("'{0}'", Url.Action("CorporationCharactersKillsMonth","Killboard"))) ,null, null, @Model.InternalId);
            evekillboard.loadCorporationCharactersLossesMonth(@Html.Raw(string.Format("'{0}'", Url.Action("CorporationCharactersLossesMonth","Killboard"))),null, null, @Model.InternalId);
            evekillboard.loadCorporationContribution(@Html.Raw(string.Format("'{0}'", Url.Action("CorporationContribution", "Killboard"))), @Model.InternalId, @corpAllyInternalId);
            evekillboard.loadActivity(@Html.Raw(string.Format("'{0}'", Url.Action("CorporationActivity", "Killboard"))), @Model.InternalId);
            evekillboard.loadList(@Html.Raw(string.Format("'{0}'",isKill ? Url.Action( "CorporationKills" , "Killboard") : Url.Action( "CorporationLosses" , "Killboard"))), @Model.InternalId);
        });
    </script>
    }
    else if (isCharacter){
    <script type="text/javascript" >
        $(document).ready(function () {
            evekillboard.loadCharacterShips(@Html.Raw(string.Format("'{0}'", Url.Action("CharacterShips", "Killboard"))), @Model.InternalId);
            evekillboard.loadCharacterShipGroups(@Html.Raw(string.Format("'{0}'", Url.Action("CharacterShipGroupsKills", "Killboard"))), @Model.InternalId);
            evekillboard.loadCharacterContribution(@Html.Raw(string.Format("'{0}'", Url.Action("CharacterContribution", "Killboard"))), @Model.InternalId, @charCorpInternalId);
            evekillboard.loadActivity(@Html.Raw(string.Format("'{0}'", Url.Action("CharacterActivity", "Killboard"))), @Model.InternalId);
            evekillboard.loadList(@Html.Raw(string.Format("'{0}'", isKill ? Url.Action( "CharacterKills" , "Killboard") : Url.Action( "CharacterLosses" , "Killboard"))), @Model.InternalId);
            
        });
    </script>
    }
    else if (isAlliance){
    <script type="text/javascript" >
        $(document).ready(function () {
            evekillboard.loadAllianceCorpKills(@Html.Raw(string.Format("'{0}'", Url.Action("TopAllianceCorporationKills", "Killboard"))), @Model.InternalId); 
            evekillboard.loadAllianceCorpLosses(@Html.Raw(string.Format("'{0}'", Url.Action("TopAllianceCorporationLosses", "Killboard"))),@Model.InternalId);
            evekillboard.loadActivity(@Html.Raw(string.Format("'{0}'", Url.Action("AllianceActivity", "Killboard"))), @Model.InternalId);
            evekillboard.loadList(@Html.Raw(string.Format("'{0}'", isKill ? Url.Action( "AllianceKills" , "Killboard") : Url.Action( "AllianceLosses" , "Killboard"))), @Model.InternalId);
        });
    </script>
    }
}